package com.hgy.controller;

import com.hgy.common.JsonResult;
import com.hgy.entity.Car;
import com.hgy.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author : ang
 * @Program: carSystem
 * @Title : CarController
 * @Date : 2020-08-27 19:46
 **/
@Controller
@RequestMapping("/car")
public class CarController {

    @Autowired
    private CarService carService;

    @RequestMapping("/price.do")
    @ResponseBody
    public JsonResult findByPrice(Integer getid) {
        JsonResult jsonResult = null;
        try {
            List<Car> list = carService.findByPrice(getid);
            jsonResult = new JsonResult(1, list);
        } catch (Exception e) {
            jsonResult = new JsonResult(0, e.getMessage());
        }
        return jsonResult;
    }

    @RequestMapping("/number.do")
    @ResponseBody
    public JsonResult findByNumber(Integer getid) {
        JsonResult jsonResult = null;
        try {
            List<Car> list = carService.findByNumber(getid);
            jsonResult = new JsonResult(1, list);
        } catch (Exception e) {
            jsonResult = new JsonResult(0, e.getMessage());
        }
        return jsonResult;
    }

    @RequestMapping("/findcar.do")
    @ResponseBody
    public JsonResult findCar(Integer getid) {
        JsonResult jsonResult = null;
        try {
            Car car = carService.findById(getid);
            jsonResult = new JsonResult(1,car);
        } catch (Exception e) {
            jsonResult = new JsonResult(0,e.getMessage());
        }

        return jsonResult;
    }
}
